package com.mall.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.business.domain.TProductType;
import com.mall.business.service.ITProductTypeService;
import com.mall.common.core.page.TableDataInfo;

/**
 * 商品分类Controller
 *
 * @author ruoyi
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/business/producttype" )
public class TProductTypeController extends BaseController {
    @Autowired
    private ITProductTypeService tProductTypeService;

/**
 * 查询商品分类列表
 */
//@RequiresPermissions("business:type:list")
@GetMapping("/list" )
    public TableDataInfo list(TProductType tProductType) {
        startPage();
        List<TProductType> list = tProductTypeService.selectTProductTypeList(tProductType);
        return getDataTable(list);
    }
    @GetMapping("/alllist" )
    public AjaxResult alllist( ) {
        List<TProductType> list = tProductTypeService.selectTProductTypeList(new TProductType());
        return AjaxResult.success(list);
    }


    /**
     * 导出商品分类列表
     */
    //@RequiresPermissions("business:type:export")
    @Log(title = "商品分类" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, TProductType tProductType) {
        List<TProductType> list = tProductTypeService.selectTProductTypeList(tProductType);
        ExcelUtil<TProductType> util = new ExcelUtil<TProductType>(TProductType. class);
        util.exportExcel(response, list, "商品分类数据" );
    }

    /**
     * 获取商品分类详细信息
     */
    //@RequiresPermissions("business:type:query")
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(tProductTypeService.getById(id));
    }

    /**
     * 新增商品分类
     */
    //@RequiresPermissions("business:type:add")
    @Log(title = "商品分类" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProductType tProductType) {
        return toAjax(tProductTypeService.save(tProductType));
    }

    /**
     * 修改商品分类
     */
    //@RequiresPermissions("business:type:edit")
    @Log(title = "商品分类" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProductType tProductType) {
        return toAjax(tProductTypeService.updateById(tProductType));
    }

    /**
     * 删除商品分类
     */
    //@RequiresPermissions("business:type:remove")
    @Log(title = "商品分类" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tProductTypeService.removeByIds(Arrays.asList(ids)));
    }
}
